home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr09 / vstsrc.zip / INIT.C < prev    next >
C/C++ Source or Header  |  1995-02-02  |  13KB  |  408 lines

  1. /*
  2.  * %W% %E% %U%  [EXTREL_1.2]
  3.  *
  4.  * VersaTrack orbit calculations are based on those that appear in Dr. Manfred
  5.  * Bester's sattrack program (the Unix(tm) versions 1 and 2).
  6.  *
  7.  * The data from which the maps where generated come from "xsat", an
  8.  * X-Windows program by David A. Curry (N9MSW).
  9.  *
  10.  * Site coordinates come from various sources, including a couple of
  11.  * World Almanacs, and also from both of the programs mentioned above.
  12.  *
  13.  * The following are authors' applicable copyright notices:
  14.  *
  15.  *
  16.  * Copyright (c) 1992, 1993, 1994 Manfred Bester. All Rights Reserved.        
  17.  *                                                                           
  18.  * Permission to use, copy, modify, and distribute this software and its      
  19.  * documentation for educational, research and non-profit purposes, without   
  20.  * fee, and without a written agreement is hereby granted, provided that the  
  21.  * above copyright notice and the following three paragraphs appear in all    
  22.  * copies.                                                                    
  23.  *                                                                              
  24.  * Permission to incorporate this software into commercial products may be    
  25.  * obtained from the author, Dr. Manfred Bester, 1636 M. L. King Jr. Way,     
  26.  * Berkeley, CA 94709, USA.                                                   
  27.  *                                                                             
  28.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,  
  29.  * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF    
  30.  * THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED   
  31.  * OF THE POSSIBILITY OF SUCH DAMAGE.                                         
  32.  *                                                                             
  33.  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT       
  34.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A    
  35.  * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"       
  36.  * BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,  
  37.  * UPDATES, ENHANCEMENTS, OR MODIFICATIONS.                                   
  38.  *                                                                             
  39.  *                                                                             
  40.  * Copyright 1992 by David A. Curry                                            
  41.  *                                                                             
  42.  * Permission to use, copy, modify, distribute, and sell this software and its 
  43.  * documentation for any purpose is hereby granted without fee, provided that  
  44.  * the above copyright notice appear in all copies and that both that copyright
  45.  * notice and this permission notice appear in supporting documentation.  The  
  46.  * author makes no representations about the suitability of this software for  
  47.  * any purpose.  It is provided "as is" without express or implied warranty.   
  48.  *                                                                             
  49.  * David A. Curry, N9MSW                                                       
  50.  * Purdue University                                                           
  51.  * Engineering Computer Network                                                
  52.  * 1285 Electrical Engineering Building                                        
  53.  * West Lafayette, IN 47907                                                    
  54.  * davy@ecn.purdue.edu                                                         
  55.  *                                                                             
  56.  * VersaTrack Copyright (c) 1993, 1994 Siamack Navabpour. All Rights Reserved.
  57.  *
  58.  * Permission is hereby granted to copy, modify and distribute VersaTrack
  59.  * in whole, or in part, for educational, non-profit and non-commercial use
  60.  * only, free of charge or obligation, and without agreement, provided that
  61.  * all copyrights and restrictions noted herein are observed and followed, and
  62.  * additionally, that this and all other copyright notices listed herein
  63.  * appear unaltered in all copies and in all derived work.
  64.  *
  65.  * This notice shall not in any way void or supersede any of the other authors
  66.  * rights or privileges.
  67.  *
  68.  * VersaTrack IS PRESENTED FREE AND "AS IS", WITHOUT ANY WARRANTY OR SUPPORT.
  69.  * YOU USE IT AT YOUR OWN RISK. The author(s) shall not be liable for any
  70.  * direct, indirect, incidental, or consequential damage, loss of profits or
  71.  * other tangible or intangible losses or benefits, arising out of or related
  72.  * to its use. VersaTrack carries no warranty, explicit or implied, including
  73.  * but not limited to those of merchantablity and fitness for a particular
  74.  * purpose.
  75.  *
  76.  * Siamack Navabpour, 12342 Hunter's Chase Dr. Apt. 2114, Austin, TX 78729.
  77.  * sia@bga.com or sia@realtime.com.
  78.  */
  79.  
  80.  
  81. #include <windows.h>
  82. #include <stdio.h>
  83. #include <math.h>
  84. #include <sys/types.h>
  85. #include <stdlib.h>
  86. #include <time.h>
  87.  
  88. #include "vstdefs.h"
  89. #include "vsttype.h"
  90. #include "vstextrn.h"
  91.  
  92. static reginfo_t  AppReginfo = {
  93.     "VersaTrack",       /* message */
  94.     "VersaTrack\\",     /* Basekey (if followed by subkey, must have \\ at end) */
  95.     VersionStr,         /* Subkey 1 (if not the last one, must have \\ at end) */
  96.     "",                 /* Subkey 2 (ditto) */
  97.     "",                 /* Subkey 3 (ditto) */
  98.     NULL,
  99. };
  100.  
  101. static registry_t AppRegs [] = {
  102.     "Please enter the full directory path name where VersaTrack can \
  103. find its maps, satellite, site, mode and active data files:",
  104.     datadir,
  105.     datadir,
  106.     sizeof(datadir),
  107.     0,
  108.     "Data Directory",
  109.     REG_SZ,
  110.  
  111.     "Enter the name of the satellite 2-line element sets file:",
  112.     "tle.dat",
  113.     satfilename,
  114.     sizeof(satfilename),
  115.     0,
  116.     "TLE File",
  117.     REG_SZ,
  118.  
  119.     "Enter the name of the file containing the site information:",
  120.     "sites.dat",
  121.     sitefilename,
  122.     sizeof(sitefilename),
  123.     0,
  124.     "Sites File",
  125.     REG_SZ,
  126.  
  127.     "Enter the name of the modes files:",
  128.     "modes.dat",
  129.     modesfilename,
  130.     sizeof(modesfilename),
  131.     0,
  132.     "Modes File",
  133.     REG_SZ,
  134.  
  135.     "Enter the name of the rotator-control definition file:",
  136.     "rotator.dat",
  137.     rotatorfilename,
  138.     sizeof(rotatorfilename),
  139.     0,
  140.     "Rotator List",
  141.     REG_SZ,
  142.  
  143.     "Enter the name of the radio-control definition file:",
  144.     "radio.dat",
  145.     radiofilename,
  146.     sizeof(radiofilename),
  147.     0,
  148.     "Radio List",
  149.     REG_SZ,
  150.  
  151.     "Enter the name of the file containing the active list:",
  152.     "active.dat",
  153.     activefilename,
  154.     sizeof(activefilename),
  155.     0,
  156.     "Active File",
  157.     REG_SZ,
  158.  
  159.     "Enter the name of default map to be drawn upon VersaTrack startup:",
  160.     "world",
  161.     mapname,
  162.     sizeof(mapname),
  163.     0,
  164.     "Default Map",
  165.     REG_SZ,
  166.  
  167.     "Enter the name of your location. For example \"Denver, Colorado\". \
  168. After the installation make sure sites file contains an entry for it.",
  169.     "Austin, Texas",
  170.     SiteName,
  171.     sizeof(SiteName),
  172.     0,
  173.     "Default GSName",
  174.     REG_SZ,
  175.  
  176.     "Enter the 3-letter name of your time zone",
  177.     "CST",
  178.     timeZoneName,
  179.     sizeof(timeZoneName),
  180.     0,
  181.     "TZName",
  182.     REG_SZ,
  183.  
  184.     "Enter the present offset in hours (and decimal fractions) between \
  185. your time zone and UTC. A negative value indicates \"west\" of UTC:",
  186.     "-6.0",
  187.     timeZoneHrs,
  188.     sizeof(timeZoneHrs),
  189.     0,
  190.     "TZDiff",
  191.     REG_SZ,
  192.         
  193. #if 0
  194.     NULL,
  195.     NULL,
  196.     EpochString,
  197.     sizeof(EpochString),
  198.     sizeof(EpochString),    
  199.     "Settings",
  200.     REG_BINARY,
  201. #endif
  202. };
  203.  
  204. #define NAPPREGS    (sizeof(AppRegs) / sizeof(AppRegs[0]))
  205.  
  206. BOOL
  207. init_main()
  208. {
  209.     satellite_t ** (*readSatDB)(int, char *, char *, char *);
  210.     site_t ** (*readSiteDB)(int, char *, char *, unsigned char *, char *);
  211.     BOOL (*readSatmodeDB)(int, HWND, satellite_t **, char *, char *, char *);
  212.     BOOL (*readRotDB)(int, HWND, rotinfo_t **, char *, char *, char *);
  213.     BOOL (*readRadDB)(int, HWND, radinfo_t **, char *, char *, char *);
  214.     BOOL (*GetRegistryValues)(int, HWND, registry_t *, reginfo_t *, int, int);
  215.     int  len;
  216.     satellite_t **sapp;
  217.     site_t **sipp;
  218.     extern void *LibFunc(const char *), LibClose(void);
  219.  
  220.     srand(time(0));
  221.     
  222.     InitializeCriticalSection(&display_mutex);
  223.     InitializeCriticalSection(&sat_mutex);
  224.  
  225.     strcpy(gtrfilename,".\\gtr.out");
  226.     GetCurrentDirectory(sizeof(datadir), datadir);
  227.     lowerCase(datadir);
  228.  
  229.     selInfo = NULL;
  230.     currentSel = NULL;
  231.  
  232.     GetRegistryValues = (void (*)) LibFunc("GetRegistryValues");
  233.     if (GetRegistryValues == NULL)
  234.         goto nogo;
  235.  
  236. #ifdef _DEBUG_
  237.     diag("calling GetRegistryValues\n");
  238. #endif /* _DEBUG_ */
  239.  
  240.     textbuf[0] = 0;
  241.     len = 64;
  242.     GetUserName(textbuf, &len);
  243.     AppReginfo.ri_username = textbuf;
  244.     
  245.     if (!(*GetRegistryValues)(VSTVERSION, Gwnd, AppRegs, &AppReginfo, NAPPREGS, TRUE))
  246.         goto nogo;
  247.  
  248. #ifdef _DEBUG_
  249.     diag("Got registry values.\n");
  250. #endif /* _DEBUG_ */
  251.     if ((timeZoneHrs[0] != '-' && timeZoneHrs[0] != '+') &&
  252.         !((timeZoneHrs[0] >= '0') && (timeZoneHrs[0] <= '9')) &&
  253.         timeZoneHrs[0] != '.') {
  254.             usermsg("Invalid installed value for TimeZone. Set to UTC");
  255.         strcpy(timeZoneHrs,"0.0");
  256.         strcpy(timeZoneName,"UTC");
  257.     }
  258.     if ((timeZoneHrs[0] == '-' || timeZoneHrs[0] == '+' ||
  259.         timeZoneHrs[0] == '.') && !(timeZoneHrs[1] >= '0' &&
  260.         timeZoneHrs[1] <= '9')) {
  261.             usermsg("Invalid installed value for TimeZone. Set to UTC");
  262.         strcpy(timeZoneHrs,"0.0");
  263.         strcpy(timeZoneName,"UTC");
  264.     }
  265.     timeZone = atof(timeZoneHrs) / 24.0;
  266.     if (timeZoneName[0] == 0)
  267.         strcpy(timeZoneName,"???");
  268.  
  269. #ifdef _DEBUG_
  270.     diag("Reading site DB\n");
  271. #endif /* _DEBUG_ */
  272.  
  273.     readSiteDB = (void(*)) LibFunc("readSiteDB");
  274.     if (readSiteDB == NULL)
  275.         goto nogo;
  276.  
  277.     if (!(siteInfo = (*readSiteDB)(VSTVERSION, datadir, sitefilename,
  278. #if 0
  279.             EpochString, tmpbuf))) {
  280. #else
  281.             NULL, tmpbuf))) {
  282. #endif
  283.         usermsg(tmpbuf);
  284.     }
  285.  
  286.    for (NSites=0, sipp = siteInfo; sipp && *sipp; sipp++, NSites++) ;
  287. #ifdef _DEBUG_
  288.     diag("Reading Sat DB\n");
  289. #endif /* _DEBUG_ */
  290.  
  291.     if (!(readSatDB = (void(*)) LibFunc("readSatDB")))
  292.         goto nogo;
  293.  
  294.     if (!(satInfo = (*readSatDB)(VSTVERSION, datadir, satfilename, tmpbuf))) {
  295.         usermsg(tmpbuf);
  296.     }
  297.  
  298.     for (NSats=0, sapp = satInfo; sapp && *sapp; sapp++, NSats++) ;
  299.     
  300. #ifdef _DEBUG_
  301.     diag("Reading Mode DB\n");
  302. #endif /* _DEBUG_ */
  303.  
  304.     if (!(readSatmodeDB = (void(*)) LibFunc("readSatmodeDB")))
  305.         goto nogo;
  306.  
  307.     if (!(*readSatmodeDB)(VSTVERSION, Gwnd, satInfo, datadir, modesfilename, tmpbuf))
  308.         usermsg(tmpbuf);
  309.  
  310. #ifdef _DEBUG_
  311.     diag("Reading Rotator DB\n");
  312. #endif /* _DEBUG_ */
  313.  
  314.     if (!(readRotDB = (void(*)) LibFunc("readRotDB")))
  315.         goto nogo;
  316.  
  317.     if (!(*readRotDB)(VSTVERSION, Gwnd, &rotInfo, datadir, rotatorfilename, tmpbuf))
  318.         usermsg(tmpbuf);
  319.  
  320. #ifdef _DEBUG_
  321.     diag("Reading Radio DB\n");
  322. #endif /* _DEBUG_ */
  323.  
  324.     if (!(readRadDB = (void(*)) LibFunc("readRadDB")))
  325.         goto nogo;
  326.  
  327.     if (!(*readRadDB)(VSTVERSION, Gwnd, &radInfo, datadir, radiofilename, tmpbuf))
  328.         usermsg(tmpbuf);
  329.  
  330.     LibClose();
  331.  
  332. #ifdef _DEBUG_
  333.     diag("reading active DB\n");
  334. #endif /* _DEBUG_ */
  335.  
  336.     if (!findSitebyName(SiteName)) {
  337.         sprintf(tmpbuf,"Cannot find \"%s\" in the site database. You may \
  338. run into problems...", SiteName);
  339.         usermsg(tmpbuf);
  340.     }
  341.  
  342.     readactiveDB();
  343.  
  344. #ifdef _DEBUG_
  345.     diag("init_main finished sucessfully\n");
  346. #endif /* _DEBUG_ */
  347.     return TRUE;
  348.     
  349. nogo:
  350.     LibClose();
  351. #ifdef _DEBUG_
  352.     diag("init_main: +++ INIT FAILED +++\n");
  353. #endif /* _DEBUG_ */
  354.     usermsg(dllinvalidmsg);
  355.     return FALSE;
  356. }
  357.  
  358.  
  359. BOOL
  360. UnInstall(version)
  361. int version;
  362. {
  363.     void (*RegClean)(int, HANDLE, reginfo_t *);
  364.     extern void *LibFunc(const char *), LibClose(void);
  365.     int len;
  366.  
  367.     RegClean = (void (*)) LibFunc("RegCleanup");
  368.     if (RegClean == NULL) {
  369.         LibClose();
  370.         usermsg(dllinvalidmsg);
  371.         return FALSE;
  372.     }
  373.  
  374.     textbuf[0] = 0;
  375.     len = 64;
  376.     GetUserName(textbuf, &len);
  377.     AppReginfo.ri_username = textbuf;
  378.  
  379.     sprintf(tmpbuf, "%s is about to be un-installed for \"%s\". Do you want to proceed ?",
  380.         VersionStr, textbuf);
  381.     
  382.     if (!yesno(tmpbuf)) {
  383.         LibClose();
  384.         return FALSE;
  385.     }
  386.     
  387.     (*RegClean)(version, NULL, &AppReginfo);
  388.  
  389.     LibClose();
  390.     return TRUE;
  391. }
  392.  
  393.  
  394. void
  395. copyrights()
  396. {
  397.     void (*crmsg)(int, HWND);
  398.     extern void *LibFunc(const char *), LibClose(void);
  399.  
  400.     crmsg = (void (*)) LibFunc("Copyright");
  401.     if (crmsg == NULL) {
  402.         LibClose();
  403.         fatal(dllinvalidmsg);
  404.     }
  405.     (*crmsg)(VSTVERSION, Gwnd);
  406.     LibClose();
  407. }
  408.